package com.fdb.efp.cus.service.impl;

import java.util.List;
import java.util.Objects;

import com.fdb.efp.cus.service.dao.CusIndivCreatesTempDao;
import com.fdb.efp.cus.service.domain.CusIndivCreatesTemp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.cus.service.facade.CusIndivCreatesTempService;
import com.fdb.efp.cus.service.vo.CusIndivCreatesTempVO;

/**
 * Service Impl: 客户建档信息临时表服务实现
 * 
 * @author ligm
 * @date 2019-05-06
 */
@Service("cusIndivCreatesTempService")
public class CusIndivCreatesTempServiceImpl implements CusIndivCreatesTempService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(CusIndivCreatesTempServiceImpl.class);

	@Autowired
	private CusIndivCreatesTempDao cusIndivCreatesTempDao;

	/**
	 * 新增数据
	 * 
	 * @param inCusIndivCreatesTempVo
	 * @return
	 */
	public int insertCusIndivCreatesTemp(CusIndivCreatesTempVO inCusIndivCreatesTempVo) {
		logger.debug("当前新增数据为:" + inCusIndivCreatesTempVo.toString());
		int num = 0;
		try {
			CusIndivCreatesTemp cusIndivCreatesTemp = new CusIndivCreatesTemp();
			beanCopy(inCusIndivCreatesTempVo, cusIndivCreatesTemp);
			num = cusIndivCreatesTempDao.insertCusIndivCreatesTemp(cusIndivCreatesTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 根据主键删除信息
	 * 
	 * @param inCusIndivCreatesTempVo
	 * @return
	 */
	public int deleteByPk(CusIndivCreatesTempVO inCusIndivCreatesTempVo) {
		logger.debug("当前删除数据条件为:" + inCusIndivCreatesTempVo);
		int num = 0;
		try {
			CusIndivCreatesTemp cusIndivCreatesTemp = new CusIndivCreatesTemp();
			beanCopy(inCusIndivCreatesTempVo, cusIndivCreatesTemp);
			num = cusIndivCreatesTempDao.deleteByPk(cusIndivCreatesTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inCusIndivCreatesTempVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 根据主键更新信息
	 * 
	 * @param inCusIndivCreatesTempVo
	 * @return
	 */
	public int updateByPk(CusIndivCreatesTempVO inCusIndivCreatesTempVo) {
		logger.debug("当前修改数据为:" + inCusIndivCreatesTempVo.toString());
		int num = 0;
		try {
			CusIndivCreatesTemp cusIndivCreatesTemp = new CusIndivCreatesTemp();
			beanCopy(inCusIndivCreatesTempVo, cusIndivCreatesTemp);
			num = cusIndivCreatesTempDao.updateByPk(cusIndivCreatesTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inCusIndivCreatesTempVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 根据主键查询详情
	 * 
	 * @param cusIndivCreatesTemp
	 * @return
	 */
	public CusIndivCreatesTempVO queryByPk(CusIndivCreatesTempVO inCusIndivCreatesTempVo) {

		logger.debug("当前查询参数信息为:" + inCusIndivCreatesTempVo);
		try {
			CusIndivCreatesTemp queryCusIndivCreatesTemp = new CusIndivCreatesTemp();
			beanCopy(inCusIndivCreatesTempVo, queryCusIndivCreatesTemp);
			CusIndivCreatesTemp queryRslCusIndivCreatesTemp = cusIndivCreatesTempDao.queryByPk(queryCusIndivCreatesTemp);
			if (Objects.nonNull(queryRslCusIndivCreatesTemp)) {
				CusIndivCreatesTempVO outCusIndivCreatesTempVo = beanCopy(queryRslCusIndivCreatesTemp, new CusIndivCreatesTempVO());
				logger.debug("当前查询结果为:" + outCusIndivCreatesTempVo.toString());
				return outCusIndivCreatesTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 一级数据权限
	 * 
	 * @param cusIndivCreatesTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CusIndivCreatesTempVO> queryAllByLevelOne(CusIndivCreatesTempVO cusIndivCreatesTempVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<CusIndivCreatesTempVO> list = null;
		try {
			List<CusIndivCreatesTemp> cusIndivCreatesTemps = cusIndivCreatesTempDao.queryAllByLevelOneByPage(cusIndivCreatesTempVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:" + cusIndivCreatesTemps.size());
			pageSet(cusIndivCreatesTemps, cusIndivCreatesTempVo);
			list = (List<CusIndivCreatesTempVO>) beansCopy(cusIndivCreatesTemps, CusIndivCreatesTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 二级数据权限
	 * 
	 * @param cusIndivCreatesTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CusIndivCreatesTempVO> queryAllByLevelTwo(CusIndivCreatesTempVO cusIndivCreatesTempVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<CusIndivCreatesTemp> cusIndivCreatesTemps = cusIndivCreatesTempDao.queryAllByLevelTwoByPage(cusIndivCreatesTempVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:" + cusIndivCreatesTemps.size());
		List<CusIndivCreatesTempVO> list = null;
		try {
			pageSet(cusIndivCreatesTemps, cusIndivCreatesTempVo);
			list = (List<CusIndivCreatesTempVO>) beansCopy(cusIndivCreatesTemps, CusIndivCreatesTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 三级数据权限
	 * 
	 * @param cusIndivCreatesTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CusIndivCreatesTempVO> queryAllByLevelThree(CusIndivCreatesTempVO cusIndivCreatesTempVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<CusIndivCreatesTemp> cusIndivCreatesTemps = cusIndivCreatesTempDao.queryAllByLevelThreeByPage(cusIndivCreatesTempVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:" + cusIndivCreatesTemps.size());
		List<CusIndivCreatesTempVO> list = null;
		try {
			pageSet(cusIndivCreatesTemps, cusIndivCreatesTempVo);
			list = (List<CusIndivCreatesTempVO>) beansCopy(cusIndivCreatesTemps, CusIndivCreatesTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 四级数据权限
	 * 
	 * @param cusIndivCreatesTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CusIndivCreatesTempVO> queryAllByLevelFour(CusIndivCreatesTempVO cusIndivCreatesTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<CusIndivCreatesTemp> cusIndivCreatesTemps = cusIndivCreatesTempDao.queryAllByLevelFourByPage(cusIndivCreatesTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:" + cusIndivCreatesTemps.size());
		List<CusIndivCreatesTempVO> list = null;
		try {
			pageSet(cusIndivCreatesTemps, cusIndivCreatesTempVo);
			list = (List<CusIndivCreatesTempVO>) beansCopy(cusIndivCreatesTemps, CusIndivCreatesTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 五级数据权限
	 * 
	 * @param cusIndivCreatesTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CusIndivCreatesTempVO> queryAllByLevelFive(CusIndivCreatesTempVO cusIndivCreatesTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<CusIndivCreatesTemp> cusIndivCreatesTemps = cusIndivCreatesTempDao.queryAllByLevelFiveByPage(cusIndivCreatesTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:" + cusIndivCreatesTemps.size());
		List<CusIndivCreatesTempVO> list = null;
		try {
			pageSet(cusIndivCreatesTemps, cusIndivCreatesTempVo);
			list = (List<CusIndivCreatesTempVO>) beansCopy(cusIndivCreatesTemps, CusIndivCreatesTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 
	 * 分页查询【客户建档信息临时表】 <br>
	 * 0.1:ludayong:2019年5月7日 上午9:46:30:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年5月7日 上午9:46:30
	 * @date 2019年5月7日 上午9:46:30
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<CusIndivCreatesTempVO> queryByPage(CusIndivCreatesTempVO cusIndivCreatesTempVO) {
		String msg1 = "分页查询客户建档信息临时表";
		logger.debug(msg1, "message {}");
		List<CusIndivCreatesTempVO> list = null;
		try {
			List<CusIndivCreatesTemp> CusIndivCreatesTemps = cusIndivCreatesTempDao.queryByPage(cusIndivCreatesTempVO);
			list = (List<CusIndivCreatesTempVO>) beansCopy(CusIndivCreatesTemps, CusIndivCreatesTempVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);

		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}

	/**
	 * 
	 * 统计【客户建档信息临时表】数据量 <br>
	 * 0.1:ludayong:2019年5月7日 上午9:46:30:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年5月7日 上午9:46:30
	 * @date 2019年5月7日 上午9:46:30
	 * @version 0.1
	 */
	@Override
	public int queryCount() {
		String msg1 = "查询【客户建档信息临时表】表中数据量大小";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = cusIndivCreatesTempDao.queryCount();
		} catch (Exception e) {
			String msg2 = "查询【客户建档信息临时表】表中数据量大小出错：" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}
}
